package com.harbor.java;


import com.harbor.java.domain.Fruit;
import com.harbor.java.domain.ShoppingCart;
import com.harbor.java.domain.SuperMarket;

public class Main {
    public static void main(String[] args) {
        // 初始化超市
        SuperMarket supermarket = new SuperMarket();
        // 初始化添加苹果和草莓
        Fruit f1 = new Fruit(1, "苹果", 8);
        Fruit f2 = new Fruit(2, "草莓", 13);
        int f1Id = supermarket.addFruit(f1);
        int f2Id = supermarket.addFruit(f2);

        // 题目1：求f(x ,y)
        int x = 3, y = 5, z = 3;
        ShoppingCart shoppingCart1 = new ShoppingCart();
        shoppingCart1.addItem(f1Id, x);
        shoppingCart1.addItem(f2Id, y);
        double price1 = supermarket.settlementPrice(shoppingCart1);
        System.out.printf("顾客A购买了%d斤苹果(%s/kg)、%d斤草莓(%s/kg)，价格=%.2f\n", x, f1.getPricePerKg(), y, f2.getPricePerKg(), price1);

        // 题目2：超市增加芒果，定价20元/斤。求f(x, y, z)
        Fruit f3 = new Fruit(3, "芒果", 20);
        int f3Id = supermarket.addFruit(f3);
        shoppingCart1.addItem(f3Id, z);

        double price2 = supermarket.settlementPrice(shoppingCart1);
        System.out.printf("顾客B购买了%d斤苹果(%s/kg)、%d斤草莓(%s/kg)、%d斤芒果(%s/kg)，价格=%.2f\n", x, f1.getPricePerKg(), y, f2.getPricePerKg(), z, f3.getPricePerKg(), price2);

        // 题目3：草莓打8折；求f(x, y, z)
        f2.setDiscount(0.8);

        double price3 = supermarket.settlementPrice(shoppingCart1);
        System.out.printf("顾客C购买了%d斤苹果(%s/kg)、%d斤草莓(%s/kg)、%d斤芒果(%s/kg)，草莓8折，价格=%.2f\n", x, f1.getPricePerKg(), y, f2.getPricePerKg(), z, f3.getPricePerKg(), price3);

        // 题目4：满100减10，求f(x, y, z)
        supermarket.startDiscountPromotion(100, 10);

        double price4 = supermarket.settlementPrice(shoppingCart1);
        System.out.printf("顾客D购买了%d斤苹果(%s/kg)、%d斤草莓(%s/kg)、%d斤芒果(%s/kg)，草莓8折，超市满100减10，价格=%.2f\n", x, f1.getPricePerKg(), y, f2.getPricePerKg(), z, f3.getPricePerKg(), price4);
    }
}